package com.ryskoo.controller.vendortemplaterel;

import com.ryskoo.catering.vendortemplaterel.domain.VendorTemplateRelPO;
import com.ryskoo.catering.vendortemplaterel.service.IVendorTemplateRelService;
import com.ryskoo.catering.vendortemplatereldetail.service.IVendorTemplateRelDetailService;
import com.ryskoo.customer.vendor.domain.VendorPO;
import com.ryskoo.framework.core.bean.ReturnCodeEnum;
import com.ryskoo.framework.core.bean.ReturnMessageDTO;
import com.ryskoo.framework.core.controller.BasicHandler;
import com.ryskoo.framework.core.utils.LoginUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller("vendorTemplateRelController")
@RequestMapping("/vendor/vendortemplaterel")
public class VendorTemplateRelController extends BasicHandler<VendorTemplateRelPO>{

    private static final String TEMPLATE_PATH = "system/vendortemplaterel";

    private static final String MODULE_NAME = "VendorTemplateRel";
    
    private IVendorTemplateRelService vendorTemplateRelService;

    @Autowired
    private IVendorTemplateRelDetailService vendorTemplateRelDetailService;

    /**
     * 基类构造方法.
     */
    public VendorTemplateRelController() {
        super(TEMPLATE_PATH, MODULE_NAME);
    }

    @Autowired
    protected void setService(IVendorTemplateRelService vendorTemplateRelService) {
        this.vendorTemplateRelService = vendorTemplateRelService;
        super.setService(vendorTemplateRelService);
    }

    /**
     * 规格设置
     * @return
     */
    @GetMapping("/setSpec")
    public String setSpec(Model model){
        VendorPO vendor = LoginUtil.getLoginVendorModel();
        List<VendorTemplateRelPO> list = vendorTemplateRelService.getAllRelsByVendorUuid(vendor.getUuid(),false,true);
        model.addAttribute("templateRelList", list);
        return TEMPLATE_PATH + "/" + MODULE_NAME + "Set";
    }

    @ResponseBody
    @PostMapping("/changeStatus")
    public ReturnMessageDTO changeStatus(@RequestParam String detailUuid, @RequestParam boolean status){
        vendorTemplateRelDetailService.changeStatus(detailUuid, status);
        ReturnMessageDTO returnMessageDTO = new ReturnMessageDTO();
        returnMessageDTO.setReturnCode(ReturnCodeEnum.SUCCESS.getReturnCode());
        returnMessageDTO.setReturnNote("状态设置成功");
        return returnMessageDTO;
    }
}
